package com.kcs.fxmargin.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.kcs.fxmargin.model.CConfigSys;
import com.kcs.fxmargin.model.CMessage;
import com.kcs.fxmargin.service.CommonService;
import com.kcs.fxmargin.service.MessageService;

public class ContextListener implements ServletContextListener {
	
	CommonService common = new CommonService();
	
	public static Map<String, String> properties = new HashMap<String, String>();
	
	public static String fxmarginmessage0001 = "";
	public static String fxmarginmessage0002 = "";
	public static String fxmarginmessage0003 = "";
	public static String fxmarginmessage0004 = "";
	public static String fxmarginmessage0005 = "";
	public static String fxmarginmessage0006 = "";
	public static String fxmarginmessage0007 = "";
	public static String fxmarginmessage0008 = "";
	public static String fxmarginmessage0009 = "";
	public static String fxmarginmessage0010 = "";
	public static String fxmarginmessage0011 = "";
	public static String fxmarginmessage0012 = "";
	public static String fxmarginmessage0013 = "";
	public static String fxmarginmessage0014 = "";
	public static String fxmarginmessage0015 = "";
	public static String fxmarginmessage0016 = "";
	public static String fxmarginmessage0017 = "";
	public static String fxmarginmessage0018 = "";
	public static String fxmarginmessage0019 = "";
	public static String fxmarginmessage0020 = "";
	public static String fxmarginmessage0021 = "";
	public static String fxmarginmessage0022 = "";
	public static String fxmarginmessage0023 = "";
	public static String fxmarginmessage0024 = "";
	
	
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		System.out.println("contextDestroyed : Start");
		
    	try {
    		
    	
        } catch (Exception e){
        	e.printStackTrace();
        }
    	
		System.out.println("contextDestroyed : End");
	}

	public void contextInitialized(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		System.out.println("contextInitialized : Start");
		MessageService service = new MessageService();
    	try {
    		
    		System.out.println("getMessage");
    		
    		List<CMessage> messageList = service.getMessage();

    		if(messageList != null) {
    			fxmarginmessage0001 = messageList.get(0).getNameEN();
    			fxmarginmessage0002 = messageList.get(1).getNameEN();
    			fxmarginmessage0003 = messageList.get(2).getNameEN();
    			fxmarginmessage0004 = messageList.get(3).getNameEN();
    			fxmarginmessage0005 = messageList.get(4).getNameEN();
    			fxmarginmessage0006 = messageList.get(5).getNameEN();
    			fxmarginmessage0007 = messageList.get(6).getNameEN();
    			fxmarginmessage0008 = messageList.get(7).getNameEN();
    			fxmarginmessage0009 = messageList.get(8).getNameEN();
    			fxmarginmessage0010 = messageList.get(9).getNameEN();
    			fxmarginmessage0011 = messageList.get(10).getNameEN();
    			fxmarginmessage0012 = messageList.get(11).getNameEN();
    			fxmarginmessage0013 = messageList.get(12).getNameEN();
    			fxmarginmessage0014 = messageList.get(13).getNameEN();
    			fxmarginmessage0015 = messageList.get(14).getNameEN();
    			fxmarginmessage0016 = messageList.get(15).getNameEN();
    			fxmarginmessage0017 = messageList.get(16).getNameEN();
    			fxmarginmessage0018 = messageList.get(17).getNameEN();
    			fxmarginmessage0019 = messageList.get(18).getNameEN();
    			fxmarginmessage0020 = messageList.get(19).getNameEN();
    			fxmarginmessage0021 = messageList.get(20).getNameEN();
    			fxmarginmessage0022 = messageList.get(21).getNameEN();
    			fxmarginmessage0023 = messageList.get(22).getNameEN();
    			fxmarginmessage0024 = messageList.get(23).getNameEN();
    		}
    		
    		
//    		List<CConfigSys> configList = common.getConfig();
//    		
//    		for(CConfigSys config : configList){
//    			properties.put(config.getKeys(), config.getValue());
//    		}
    	
    	} catch (IOException ex) {
    		ex.printStackTrace();
        } catch (Exception e){
        	e.printStackTrace();
        }
		
		System.out.println("contextInitialized : End");
	}


}
